import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:hive_flutter/hive_flutter.dart';
import 'package:ichinesereader/constants.dart';
import 'package:ichinesereader/controller/cache.dart';
import 'package:ichinesereader/routes/routePages.dart';
import 'package:ichinesereader/themes/pageStyles.dart';
import 'package:ichinesereader/utils/log.dart';
import 'package:ichinesereader/widgets/buttons/floatingActionButtonAddBooksToFolder.dart';
import 'package:ichinesereader/widgets/layouts/appdrawerIndividual.dart';
import 'package:ichinesereader/widgets/layouts/customAppBar.dart';
import 'package:ichinesereader/widgets/module/leveledReadingBody.dart';
import 'package:ichinesereader/widgets/sidebars/individualSidebar.dart';
import '../../controller/books.dart';
import '../../models/book/BookSearchDto.dart';

class IndividualLeveledReadingsScreen extends StatelessWidget {
  final box = Hive.box('appconfig');
  static const String routeName = '/individual/leveledreadings';

  @override
  Widget build(BuildContext context) {
    Log.debug('build IndividualLeveledReadingsScreen');
    // intialiaze search items
    final BookSearchDto dto = new BookSearchDto();
    final BooksController _booksController = Get.find();
    _booksController.setBookSearchDto(dto);

    int _selectedSidebarItem = RoutePages.individualPageItems
        .indexWhere((page) => page.route == Get.currentRoute);

    bool isIndividual = box.get(CacheManagerKey['nanhairole'].toString()) ==
        Constants.NanhaiRole_Individual;
    final PageStyles _pageStyles = PageStyles();
    final isSmallScreen =
        MediaQuery.of(context).size.width < Constants.DefinedScreenSmallSize;
    final isBigScreen =
        MediaQuery.of(context).size.width > Constants.DefinedScreenBigSize;

    return Scaffold(
      appBar: isSmallScreen ? CustomAppBar(title: 'Leveled Readings'.tr) : null,
      drawer: isSmallScreen ? IndividualAppDrawer() : null,
      body: Container(
        decoration: _pageStyles.pageBoxDecoration(),
        child: Row(
          children: [
            Container(
              child: Visibility(
                  visible: !isSmallScreen,
                  child: Container(
                      child: IndividualSidebarX(
                          selectedIndex: _selectedSidebarItem,
                          isBigScreen: isBigScreen))),
            ),
            Expanded(
              child: Container(
                  margin: _pageStyles.mainContainerWithPaginationEdgeInsets(),
                  child: isIndividual ? LeveledReadingBody() : Text('')),
            ),
          ],
        ),
      ),
      floatingActionButton: FloatingActionButtonAddBookToFolder(
        readingType: NanhaiBookReadingTypes.leveled,
      ),
    );
  }
}
